#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 5e5+10;
const int mod = 1e9+7;
const int inv2 = (mod+1)/2;

int n,k,x[N];
ll tr[3][N],ans,ff,gg;

ll qp(ll x,int t){ll res=1;for(;t;t>>=1,x=x*x%mod)if(t&1)res=res*x%mod;return res;}

ll inv(ll x){return qp(x,mod-2);}

void add(int t,int x,int y){for(;x<=n;x+=x&-x) (tr[t][x] += y) %= mod;}
ll query(int t,int x,ll v = 0){for(;x;x-=x&-x) (v += tr[t][x]) %= mod;return v;}

struct matrix{
	ll arr[7][7];
	void clear(){memset(arr,0,sizeof(arr));}
	const ll* operator [](int x) const{return arr[x];}
	ll* operator [](int x){return arr[x];}
	friend matrix operator * (matrix a,matrix b){
		matrix res; res.clear();
		for(int i = 0;i < 7;i++)
			for(int j = 0;j < 7;j++)
				if(a[i][j])
					for(int k = 0;k < 7;k++)
						res[i][k] = (res[i][k] + a[i][j] * b[j][k] % mod) % mod;
		return res;
	}
}now,per;

ll C(int x){return 1ll * x * (x - 1) / 2 % mod;}

ll F(int x){return now[0][x];}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in;
	for(int i = 1;i <= n;i++) x[i] = in;
	per = matrix{{
		{C(n-2) , 1 , n-2, 0, n-2 , 0 , 0},
		{1 , C(n-2) , 0 , n-2 , 0 , n-2 , 0},
		{1 , 0 , (C(n-2)+n-3) % mod , 1 , 0 , 1 , n-3},
		{0 , 1 , 1 , (C(n-2)+n-3) % mod , 1 , 0 , n-3},
		{1 , 0 , 0 , 1 , (C(n-2)+n-3) % mod , 1 , n-3},
		{0 , 1 , 1 , 0 , 1 , (C(n-2)+n-3) % mod , n-3},
		{0 , 0 , 1 , 1 , 1 , 1 , (C(n-2)+2*(n-4)+1) % mod}
		}}; 
	now[0][0] = 1;
	for(int t = k;t;t>>=1,per=per*per) if(t&1) now = now * per;
	ll iinv = inv(n-2);
	for(int i = 1;i <= n;i++){
		ll a = query(0,x[i]),fa = query(1,x[i]),ga = query(2,x[i]);
		ll b = i - a - 1,fb  = (ff - fa + mod) % mod,gb = (gg - ga + mod) % mod;
		ans = (ans + b * F(0) % mod) % mod;
		ans = (ans + a * F(1) % mod) % mod;
		ans = (ans + b * F(2) % mod * iinv % mod * (i-2) % mod + a * F(2) % mod * iinv % mod * (n-i) % mod) % mod;
		ans = (ans + a * F(3) % mod * iinv % mod * (i-2) % mod + b * F(3) % mod * iinv % mod * (n-i) % mod) % mod;
		ans = (ans + fa * F(4) % mod * iinv % mod + gb * F(4) % mod * iinv % mod) % mod;
		ans = (ans + ga * F(5) % mod * iinv % mod + fb * F(5) % mod * iinv % mod) % mod;
		add(0,x[i],1),add(1,x[i],i-1),add(2,x[i],n-i-1); ff = (ff+i-1) % mod; gg = (gg+n-i-1) % mod;
	}
	ans += F(6) * C(n) % mod * inv2 % mod; ans = (ans % mod + mod) % mod;
	printf("%lld\n",ans);
	return 0;
}

